<?php 
class annonce_models_region extends CI_Model{
	public function __construct(){
		$this->load->database();
	}
   public function get_region($region){
   		$query = $this->db->get_where('departement_region', array('region_link' => $region), 1);
   		if($query->num_rows()){
   			$row= $query->result();
   			return $row[0];
   		}else {
   			$query = $this->db->get_where('departement_region', array('code_departement' => $region), 1);
   			if($query->num_rows()){
   				$row= $query->result();
   				return $row[0];
   			}
   		}
   		return false;
   }
   

   public function get_name_category($random=false){
   
   	$this->db->select('name');
   	$this->db->from('category');
   	$this->db->where('parent' , 0);
   	if($random) $this->db->order_by('id','random');
   	$query = $this->db->get();
   	
   	if($query->num_rows()){
   		foreach ($query->result() as $row)
   			$name[]=$row->name;
   		return implode(', ',$name);
   	}
   	return false;
   }
   
}